const name = document.querySelector('input[name="username"]');
const pwd = document.querySelector('input[name="pwd"]');
const btn = document.querySelector('input[type="submit"]');
btn.onclick = () => {
    if (name.value != "" && pwd.value != "") {
        const x = new XMLHttpRequest();
        x.open('post', 'http://localhost:8000/logon', true);
        x.setRequestHeader('Content-Type', 'application/json');
        x.send(JSON.stringify({ name: name.value, pwd: pwd.value }));
        x.onreadystatechange = function () {
            if (x.readyState === 4 && x.status === 200) {
                console.log(x.response);
                if (x.response === "true") {
                    window.open('http://localhost:8000/hPage', '_self');
                } else if (x.response === "false") {
                    alert("登录失败,用户名或密码错误");
                }
            }
        }
    }

}